package atdd.kata.core.dao;

import atdd.kata.core.dao.api.PersonDao;
import atdd.kata.core.domain.Person;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
import java.util.UUID;

public class PersonDaoImpl implements PersonDao {

    @PersistenceContext
    private EntityManager em;

    @Override
    public void create(Person person) {
        person.setId(UUID.randomUUID().toString());
        em.persist(person);
    }

    @Override
    public List<Person> getAllPersons() {
        return em.createQuery("SELECT p FROM PERSON p", Person.class).getResultList();
    }
}
